/* 
 * File:   Genome.cpp
 * Author: wasp
 * 
 * Created on December 14, 2014, 10:04 PM
 */

#include "TSPGenome.h"
#include "GA/Gene.h"
#include "GA/IntGene.h"
#include "GA/Genome.h"
#include "GA/PermutationGenome.h"
#include "Cities.h"

namespace tsp {

TSPGenome::TSPGenome(): practical::ga::PermutationGenome() {}
TSPGenome::TSPGenome(const TSPGenome& orig): practical::ga::PermutationGenome(orig) {}
TSPGenome::TSPGenome(const std::vector<practical::ga::IntGene>& genes): practical::ga::PermutationGenome(genes) {}

TSPGenome::TSPGenome(const practical::ga::PermutationGenome& other): practical::ga::PermutationGenome(other) {}
TSPGenome::~TSPGenome() {
	// die news aus shallowCopy werden wo anders zerstoert. hier ist nichts zu machen
}

double TSPGenome::fitness() const {
	double dist = 0;
	int s = genes.size();
	Cities cities = Cities::instance();
	for (int i=0; i<s; i++) {
		int n = i+1;
		if (n >= s) {
			n = 0;
		}
		practical::ga::IntGene geneC = genes.at(i);
		practical::ga::IntGene geneN = genes.at(n);
		dist += cities.distance(geneC.getValue(), geneN.getValue());
	}
	return (1/dist);
}
practical::ga::Genome* TSPGenome::shallowCopy() const {
	TSPGenome* out = new TSPGenome();
	// es gibt keine klassenvariablen...
	return out;
};

}

